// Package inventory
// @Title inventory[简述该包的主要作用]
// @Description
// @Author  cnHuaShao
// @since v0.0.1
// @Version v1.0.0
// @Date 2024/6/4 22:20
// @Update 2024/6/4 22:20
package inventory

import (
	"FinancialManagement/src/base/db"
	"fmt"
)

// GetInventoryList
// @Description: 获取库存信息列表
// @param pageSize
// @param pageNumber
// @return []Inventory
// @return int64
// @return error
func GetInventoryList(typeName string, pageSize, pageNumber int) ([]Inventory, int64, error) {
	sqlWhere := " 1=1 "
	if typeName != "" {
		sqlWhere = fmt.Sprintf("%s and type_name like '%%%s%%'", sqlWhere, typeName)
	}
	var inventoryList []Inventory
	// 计算起始行
	startPage := (pageNumber - 1) * pageSize
	var count int64
	result := db.Res.DB.GetDbR().Model(&Inventory{}).Where(sqlWhere).Order("inventory_id").Limit(pageSize).Offset(startPage).Preload("InventoryType").Find(&inventoryList).Count(&count)
	return inventoryList, count, result.Error
}
